<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>修改电子文档</title>
    <style>
        body {
            font-family: Arial, sans-serif;
        }
        .form-container {
            width: 300px;
            margin: 0 auto;
            border: 1px solid #000;
            padding: 20px;
            background-color: #e0f7e9;
        }
        .form-container h2 {
            text-align: center;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-group label {
            display: block;
            margin-bottom: 5px;
        }
        .form-group input[type="text"],
        .form-group input[type="date"],
        .form-group select,
        .form-group textarea {
            width: 100%;
            padding: 5px;
            box-sizing: border-box;
        }
        .form-group input[type="submit"],
        .form-group input[type="button"] {
            width: 48%;
            padding: 5px;
            margin-top: 5px;
        }
        .form-group input[type="submit"] {
            background-color: #4CAF50;
            color: white;
            border: none;
            cursor: pointer;
        }
        .form-group input[type="button"] {
            background-color: #f44336;
            color: white;
            border: none;
            cursor: pointer;
        }
    </style>
</head>
<body>

<div class="form-container">
    <h2>修改电子文档</h2>
    <form id="sj" method="post">
        <div class="form-group">
            <label for="doc-name">文档名称 (*)</label>
            <input type="text" id="doc-name" name="doc-name" value="" required>
        </div>
        <div class="form-group">
            <label for="doc-type">文档类型</label>
            <select id="doc-type" name="doc-type">
            </select>
        </div>
        <div class="form-group">
            <label for="doc-summary">文档摘要</label>
            <textarea id="doc-summary" name="doc-summary"></textarea>
        </div>
        <div class="form-group">
            <label for="uploader">上传人</label>
            <input type="text" id="uploader" name="uploader" value="">
        </div>
        <div class="form-group">
            <label for="upload-date">上传时间 (*)</label>
            <input type="date" id="upload-date" name="upload-date" value="2012-03-05" required>
        </div>
        <div class="form-group">
            <input type="button" id="tj" value="提交">
            <input type="button" value="返回">
        </div>
    </form>
</div>

</body>
<script src="js/jquery-1.12.4.js"></script>
<script>
    $("#tj").click(function () {
        $.ajax({
            url:"http://localhost:8080/ElectronicDocumentManagementSystem/entr/updEntr",
            type:"post",
            dataType: "json",
            contentType: "application/json;charset=utf-8",
            data:JSON.stringify({
                id:sessionStorage.getItem("id"),
                title:$('input[name="doc-name"]').val(),
                uploaduser:$('input[name="uploader"]').val(),
                createdate:$('input[name="upload-date"]').val(),
                summar:$('textarea[name="doc-summary"]').val(),
                categoryid:$('select[name="doc-type"]').val()
            }),
            success:function (data) {
                if (data.code == 200) {
                    alert("修改成功")
                    window.location.href = "index.html"
                }
            }
        })
    })
    $.get("http://localhost:8080/ElectronicDocumentManagementSystem/categor/sel", function (data) {
        console.log(data);
        $.each(data, function (index, item) {
            console.log(item);
            var html = `
                <option value="${item.id}">${item.name}</option>
                `
            ;$("select").append(html);
        })
    })
    var id = sessionStorage.getItem("id")
    setTimeout(function () {
        console.log(id);
        $.ajax(`http://localhost:8080/ElectronicDocumentManagementSystem/entr/selEntr/${id}`,{
            type:"get",
            dataType:"json",
            contentType:"application/json;charset=utf-8",
            success:function (data){
                console.log(data);
                $('input[name="doc-name"]').val(data.title);
                $('input[name="uploader"]').val(data.uploaduser);
                $('input[name="upload-date"]').val(data.createdate.substring(0, 10));
                $('textarea[name="doc-summary"]').val(data.summar);
                $('option[value='+data.categoryid+']').prop("selected", true);
            }
        })
    }, 1000)

</script>
</html>